package cn.wolfcode.shop.server.service.impl;

import cn.wolfcode.shop.api.domain.SkuProperty;
import cn.wolfcode.shop.api.domain.SkuPropertyValue;
import cn.wolfcode.shop.api.service.ISkuPropertyService;
import cn.wolfcode.shop.server.mapper.SkuPropertyMapper;
import cn.wolfcode.shop.server.mapper.SkuPropertyValueMapper;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class SkuPropertyServiceImpl implements ISkuPropertyService {

    @Autowired
    private SkuPropertyMapper skuPropertyMapper;
    @Autowired
    private SkuPropertyValueMapper skuPropertyValueMapper;

    @Override
    public int save(SkuProperty skuProperty) {
        return skuPropertyMapper.insert(skuProperty);
    }

    @Override
    public int update(SkuProperty skuProperty) {
        return skuPropertyMapper.updateByPrimaryKey(skuProperty);
    }

    @Override
    public SkuProperty get(Long id) {
        return skuPropertyMapper.selectByPrimaryKey(id);
    }

    @Override
    public int delete(Long id) {
        skuPropertyValueMapper.deleteByPropertyId(id);
        return skuPropertyMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<SkuProperty> getAll() {
        return skuPropertyMapper.selectAll();
    }

    @Override
    public List<SkuProperty> getSkuProperty(Long catalogId) {
        return skuPropertyMapper.getSkuProperty(catalogId);
    }
    @Override
    public List<SkuPropertyValue> getSkuPropertyValue(Long id) {
        return skuPropertyValueMapper.getSkuPropertyValue(id);
    }
    @Override
    public void addSkuPropertyValue(SkuPropertyValue skuPropertyValue) {
        skuPropertyValueMapper.insert(skuPropertyValue);
    }

    @Override
    public void deleteValue(Long id) {
        skuPropertyValueMapper.deleteByPrimaryKey(id);
    }
}
